package com.tjise.eduorder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjise.commonutils.R;
import com.tjise.eduorder.entity.Order;
import com.tjise.eduorder.service.OrderListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description = "订单分页")
@RestController
@RequestMapping("/eduorder/orderlist")
@Slf4j
public class OrderListController {

    @Autowired
    private OrderListService orderListService;

    @ApiOperation("订单的分页查询方法")
    @GetMapping("pageOrder/{current}/{limit}")
    public R pageListOrder(@PathVariable("current") Long current,
                            @PathVariable("limit") Long limit
    ) {
        // 调用service中的方法
        Page<Order> eduOrderPage = orderListService.pageListOrder(current, limit);
        // 获取总数
        long total = eduOrderPage.getTotal();
        // 每页数据的list集合
        List<Order> records = eduOrderPage.getRecords();
        // 将数据封装入map中
        Map<String, Object> map = new HashMap<>();
        map.put("total", total);
        map.put("rows", records);
        // 将数据返回
        return R.ok().data(map);
    }

}
